package dry.example.gui.dry;

import javax.swing.*;
import java.awt.*;

/**
 * @author zc
 */
public class Lib {

    /**
     * 获取屏幕的宽度和高度(单个显示器)
     */
    public static Integer[] getWidthHeight() {
        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
        Integer[] array = new Integer[2];
        array[0] = d.width;
        array[1] = d.height;
        return array;
    }

    public static JFrame createAndShowFrame(String title, int width, int height, Component component) {
        //false=系统自带的风格
        JFrame.setDefaultLookAndFeelDecorated(false);
        JFrame f = new JFrame(title);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setSize(width, height);
        f.getContentPane().add(component);
        //水平和垂直都居中
        f.setLocationRelativeTo(null);
        return f;
    }

    public static JMenuBar createMenuBar(JFrame frame) {
        JMenuItem menuItemExit = new JMenuItem("退出");
        menuItemExit.addActionListener(e -> System.exit(0));
        //
        JMenu menuFile = new JMenu("文件");
        menuFile.add(menuItemExit);
        //
        JMenuItem menuItemAbout = new JMenuItem("关于");
        menuItemAbout.addActionListener(e -> JOptionPane.showMessageDialog(frame, "这里是描述", "这里是标题", JOptionPane.INFORMATION_MESSAGE));
        //
        JMenu menuHelp = new JMenu("帮助");
        menuHelp.add(menuItemAbout);
        //
        JMenuBar menuBar = new JMenuBar();
        menuBar.add(menuFile);
        menuBar.add(menuHelp);
        return menuBar;
    }

    public static void main(String[] args) {
        Integer[] wh = getWidthHeight();
        System.out.println(wh[0] + "*" + wh[1]);
    }

}